package exchange.netserver;

import java.io.IOException;
import java.net.BindException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Logger;

public class Server implements Runnable {
	private static Logger log = Logger.getLogger(Server.class.getName());
	private static ServerSocket providerSocket;
	private static Socket socket;
	
	public Server() {
	}

	public void run() {
		
		try {
			providerSocket = new ServerSocket(5555, 10);
			log.info("Waiting for connection on" +
					" IP: " + InetAddress.getLocalHost().getHostAddress() +
			     	" Port : 5555" );
			
			while (true){
				socket = providerSocket.accept();
				log.info("Connection received from "
						+ socket.getInetAddress().getHostName());
			
				(new Thread( new ConnectionHandler (socket) ) ).start();
			}
			
		} catch (BindException bindExc) {
			log.warning(bindExc.getMessage());
		} catch (IOException ioException) {
			ioException.printStackTrace();
		}
	}
}
